import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store }  from '../store/store'

// custom-tab-bar/index.js
Component({
  options: {
    styleIsolation: 'shared'
  },
  behaviors: [storeBindingsBehavior],
  storeBindings : {
    store,
    fields: {
      sum: 'sum',
      myActive: 'active'
    },
    actions: {
      setActive : 'setActive'
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },
  observers: {
    'sum': function(newSum) {
      this.setData({
        'pages[1].messageInfo': newSum
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    pages: [
      {
        "pagePath": "pages/home/home",
        "text": "首页",
        "iconPath": "/images/tabs/home.png",
        "selectedIconPath": "/images/tabs/home-active.png"
      },
      {
        "pagePath": "pages/message/message",
        "text": "消息",
        "iconPath": "/images/tabs/message.png",
        "selectedIconPath": "/images/tabs/message-active.png",
        messageInfo: 2
      },
      {
        "pagePath": "pages/contact/contact",
        "text": "联系我们",
        "iconPath": "/images/tabs/contact.png",
        "selectedIconPath": "/images/tabs/contact-active.png"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      this.setActive(event.detail)
      wx.switchTab({
        url: "/" + this.data.pages[event.detail].pagePath,
      })


    },
  }
})
